package model;

/**
 * A POJO that represents one item (touple) in the item table.
 * @author Lawrence Grass
 */
public class GroceryItem {
	
	/**
	 * The name of the item
	 */
	private String item;
	
	/**
	 * The cost per each item
	 */
	private Double price;
	
	/**
	 * Is it on sale?
	 */
	private Boolean sale;
	
	/**
	 * Constructs a POJO representation of an item
	 * @param item name
	 * @param price of the item
	 * @param sale if it's on sale
	 */
	public GroceryItem(String item, Double price, Boolean sale){
		this.item = item;
		this.price = price;
		this.sale = sale;
	}
	
	/**
	 * @return the item name
	 */
	public String getItem(){
		return item;
	}
	
	/**
	 * @return the item price
	 */
	public Double getPrice(){
		return price;
	}
	
	/**
	 * @return if it's on sale
	 */
	public Boolean isOnSale(){
		return sale;
	}
	
	@Override
	public String toString(){
		return "Grocery Item: " + item + " Price, " + price + ", On sale? " + sale;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((item == null) ? 0 : item.hashCode());
		result = prime * result + ((price == null) ? 0 : price.hashCode());
		result = prime * result + ((sale == null) ? 0 : sale.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		GroceryItem other = (GroceryItem) obj;
		if (item == null) {
			if (other.item != null)
				return false;
		} else if (!item.equals(other.item))
			return false;
		if (price == null) {
			if (other.price != null)
				return false;
		} else if (!price.equals(other.price))
			return false;
		if (sale == null) {
			if (other.sale != null)
				return false;
		} else if (!sale.equals(other.sale))
			return false;
		return true;
	}
}
